<?php
include('admin.php');
$type = get_global($_GET, 'type');
$c = get_post_data();

if (!empty($c['mass_delete']) && is_array($c['mass_delete']) && count($c['mass_delete']) > 0) {
	if (!in_array($type, array('posts', 'pages', 'categories', 'comments', 'users', 'uploads'))) error('That is not a valid table.');
	if ($type == 'users' || $type == 'categories') $c['mass_delete'] = array_diff($c['mass_delete'], (array)1);
	if (count($c['mass_delete']) > 0) {
		$functions = array(
			'posts' => 'delete_post',
			'pages' => 'delete_page',
			'categories' => 'delete_category',
			'comments' => 'delete_comment',
			'users' => 'delete_user',
			'uploads' => 'delete_upload'
		);
		
		$result = $functions[$type]($c['mass_delete']);
		if ($result === true) header('Location: '.$type.'.php');
		else error('There was an error deleting the '.$type.'.');
	} else error('Please select one or more '.$type.' to delete.');
} else error('Please select one or more '.$type.' to delete.');
?>